<template>
    <div>
        <van-nav-bar title="分类" left-arrow @click-left="router.go(-1)" @click-right="" />
        <van-row>
            <van-col span="6">
                <van-sidebar v-model="active">
                    <van-sidebar-item :title="v.cat_name" v-for="(v, i) in list" :key="i" />
                </van-sidebar>

            </van-col>
            <van-col span="18">
                <div v-for="(v, i) in list[active]?.children" :key="i">
                    <div>{{ v.cat_name }}</div>
                    <van-grid :border="false" :column-num="3">
                        <van-grid-item v-for="(v,i) in v.children" :key="i" @click="todetail(v.cat_name)">
                            <van-image :src="v.cat_icon?v.cat_icon:'https://fastly.jsdelivr.net/npm/@vant/assets/apple-1.jpeg'" />
                            <div>{{ v.cat_name }}</div>
                        </van-grid-item>
                    </van-grid>

                </div>

            </van-col>
        </van-row>
        <div style="height: 5.5rem;"></div>
    </div>
</template>

<script setup>
import { categoriesApi } from '@/api/api';
import { ref } from 'vue';
const active = ref(0);
import { useRoute, useRouter } from 'vue-router'
const router = useRouter()
const route = useRoute()

let list = ref([])
const getlist = () => {
    categoriesApi().then((res) => {
        console.log(res);
        list.value = res.data.message
    })
}
getlist()


const todetail = (name) =>{
    router.push({path:'/search',query:{name:name}})
}
</script>

<style lang="scss" scoped></style>